import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
    return originalPush.call(this, location).catch(err => err)
}

const routes = [{
        path: '/',
        redirect: '/bookshelf'

    },
    {
        path: '/bookshelf',
        name: 'shujia',
        meta: {
            num: 0
        },
        component: () =>
            import ('../views/BookShelf.vue')
    },
    {
        path: '/bookcity',
        name: 'shucheng',
        meta: {
            num: 1
        },
        component: () =>
            import ('../views/BookCity.vue'),
        children: [{
                path: 'popup',
                name: 'Popup',
                meta: {
                    num: 1,
                    isBack: false
                },
                component: () =>
                    import ('../pages/myPopup.vue'),
            },
            {
                path: 'recommend',
                name: 'Recommend',
                meta: {
                    num: 1
                },
                component: () =>
                    import ('../pages/cityRecommend.vue'),
            },
            {
                path: 'free',
                name: 'Free',
                meta: {
                    num: 1
                },
                component: () =>
                    import ('../pages/cityFree.vue'),
            },
            {
                path: 'male',
                name: 'Male',
                meta: {
                    num: 1
                },
                component: () =>
                    import ('../pages/cityMale.vue'),
            },
            {
                path: 'femail',
                name: 'Femail',
                meta: {
                    num: 1
                },
                component: () =>
                    import ('../pages/cityFemail.vue'),
            },
            {
                path: 'publish',
                name: 'Publish',
                meta: {
                    num: 1
                },
                component: () =>
                    import ('../pages/cityPublish.vue'),
            },
            {
                path: 'audio',
                name: 'Audio',
                meta: {
                    num: 1
                },
                component: () =>
                    import ('../pages/cityAudio.vue'),
            },
        ]
    },
    {
        path: '/category',
        name: 'fenlei',
        meta: {
            num: 2,
            isBack: false
        },
        component: () =>
            import ('../views/Category.vue'),
        children: [{
                path: 'male',
                name: 'male',
                meta: {
                    num: 2
                },
                component: () =>
                    import ('../pages/cateMale.vue'),

            },
            {
                path: 'female',
                name: 'Female',
                meta: {
                    num: 2
                },
                component: () =>
                    import ('../pages/cateFemale.vue'),

            },
            {
                path: 'publish',
                name: 'publish',
                meta: {
                    num: 2
                },
                component: () =>
                    import ('../pages/catePublish.vue'),

            },
            {
                path: 'ting',
                name: 'Ting',
                meta: {
                    num: 2
                },
                component: () =>
                    import ('../pages/cateTing.vue'),

            },
        ]
    },
    {
        path: '/user',
        name: 'wode',
        meta: {
            num: 3
        },
        component: () =>
            import ('../views/User.vue'),
        children: [{
            path: 'login',
            name: 'Login',
            component: () =>
                import ('../pages/Login')
        }]
    },
    {
        path: '/detail',
        name: 'xiangqing',
        meta: {
            isBack: false
        },
        component: () =>
            import ('../views/bookDetail.vue'),
        children: [{
                path: 'comment',
                name: 'Comment',
                component: () =>
                    import ('../pages/allComment'),
            },
            {
                path: 'login',
                name: 'Login',
                component: () =>
                    import ('../pages/Login')
            }
        ]
    },
    {
        path: '/chapter',
        name: 'mulu',
        component: () =>
            import ('../views/bookMulu.vue')
    },
    {
        path: '/content',
        name: 'neirong',
        component: () =>
            import ('../views/bookContent.vue')
    },
    {
        path: '/rank',
        name: 'paihang',
        component: () =>
            import ('../pages/bookRank.vue')
    },
    {
        path: '/navcate',
        name: 'navcate',
        component: () =>
            import ('../views/bookNavCate.vue')
    },
]

const router = new VueRouter({
    routes
})

export default router